//
//  WheelPicManager.m
//  Buiom_7.0
//
//  Created by lanou3g on 15/10/28.
//  Copyright © 2015年 triffe. All rights reserved.
//

#import "WheelPicManager.h"

@implementation WheelPicManager
// 单例的实现
+ (WheelPicManager *)shareManager
{
    static WheelPicManager *manager = nil;
    if (manager == nil) {
        manager = [[WheelPicManager alloc] init];
    }
    return manager;
}

// 对轮播图的数据进行请求和解析
- (void)ConnectionWithBlock:(void(^)(NSMutableArray *array))block
{
    NSString *string = [NSString stringWithFormat:@"%@",@"http://api.m.mtime.cn/PageSubArea/GetRecommendationIndexInfo.api"];
    NSURL *url = [NSURL URLWithString:string];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
   // [request setHTTPMethod:@"GET"];
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        if (data == nil) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"网络连接不稳定,请重新加载" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
            return;
        }
        NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
        NSDictionary *dic1 = dictionary[@"news"];
        NSDictionary *dic2 = dictionary[@"trailer"];
        NSDictionary *dic3 = dictionary[@"topList"];
        [self.dataArray addObject:dic1];
        [self.dataArray addObject:dic2];
        [self.dataArray addObject:dic3];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            block(self.dataArray);
        });

    }];
    
        
    
    
}

-(NSMutableArray *)dataArray
{
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}





@end
